﻿using System.Text;
using Volo.Abp.DependencyInjection;

namespace FlyingEye.Common
{
    public class RabbitMQProxy : ITransientDependency
    {
        private readonly RabbitMQFactory _rabbitMQFactory;

        public RabbitMQProxy(RabbitMQFactory rabbitMQFactory)
        {
            _rabbitMQFactory = rabbitMQFactory;
        }

        public void PostMessageToWebclient(ProcessNames processName, string jsonMessage)
        {
            var model = _rabbitMQFactory.GetModel(processName);
            model.BasicPublish("amq.topic", "webclient", mandatory: false, basicProperties: null, Encoding.UTF8.GetBytes(jsonMessage));
        }

        public void PostMessageToMaterialClassification(string jsonMessage)
        {
            var model = _rabbitMQFactory.GetModel(ProcessNames.MaterialClassification);
            model.BasicPublish("amq.fanout", "client", mandatory: false, basicProperties: null, Encoding.UTF8.GetBytes(jsonMessage));
        }
    }
}
